package com.nodecollege.cloud.controller.admin;

import com.nodecollege.cloud.common.annotation.AdminLoginAnnotation;
import com.nodecollege.cloud.common.annotation.ApiAnnotation;
import com.nodecollege.cloud.common.constants.NCConstants;
import com.nodecollege.cloud.common.model.NCResult;
import com.nodecollege.cloud.common.model.QueryVO;
import com.nodecollege.cloud.common.model.po.UpmsConfig;
import com.nodecollege.cloud.service.ConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LC
 * @date 2020/2/8 15:26
 */
@RestController
@AdminLoginAnnotation
@RequestMapping("/admin/config")
public class ConfigController {

    @Autowired
    private ConfigService configService;

    @ApiAnnotation(modularName = "配置管理", description = "查询配置列表")
    @PostMapping("/getConfigList")
    public NCResult<UpmsConfig> getConfigList(@RequestBody QueryVO<UpmsConfig> queryVO) {
        if (queryVO.getData() == null){
            queryVO.setData(new UpmsConfig());
        }
        queryVO.getData().setConfigType(NCConstants.INT_0);
        return configService.getConfigList(queryVO);
    }

    @ApiAnnotation(modularName = "配置管理", description = "添加配置")
    @PostMapping("/addConfig")
    public NCResult<UpmsConfig> addConfig(@RequestBody UpmsConfig config) {
        config.setConfigType(NCConstants.INT_0);
        configService.addConfig(config);
        return NCResult.ok();
    }

    @ApiAnnotation(modularName = "配置管理", description = "修改配置")
    @PostMapping("/updateConfig")
    public NCResult<UpmsConfig> updateConfig(@RequestBody UpmsConfig config) {
        config.setConfigType(NCConstants.INT_0);
        configService.updateConfig(config);
        return NCResult.ok();
    }

    @ApiAnnotation(modularName = "配置管理", description = "删除配置")
    @PostMapping("/delConfig")
    public NCResult<UpmsConfig> delConfig(@RequestBody UpmsConfig config) {
        config.setConfigType(NCConstants.INT_0);
        configService.delConfig(config);
        return NCResult.ok();
    }
}
